<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" %>
<%@include file="/quick/include/common.jsp"%>
<c:set var="buttons">
    <input type="button" style="margin-right: 5px"   onclick="f_cancel()" value="<fmt:message key="button.cancel"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_save()" value="<fmt:message key="button.save"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_query()" value="<fmt:message key="button.query"/>"/>
    <input type="button" style="margin-right: 5px"   onclick="f_back()" value="<fmt:message key="button.back"/>"/>
</c:set>
<div id='toolbar' style="display:none">
<c:out value="${buttons}" escapeXml="false"/>
</div>
<div id='score_format_form'></div>
<script>
var renderer5,editor5,renderer2,editor2;
Ext.onReady(globalScope._ready);
Ext.onReady(function(){
    Ext.get('title').dom.style.display='none';
    var store={fields:['value','text'],data:[['01','五级制'],['02','百分制'],['03','二级制']]};
    var combo=new Ext.form.ComboBox({
	    	store:new Ext.data.SimpleStore(store),
	   	    emptyText:'请选择',
	   	    fieldLabel:'成绩形式',
		    mode:'local',
		    triggerAction:'all',
		    valueField:'value',
		    displayField:'text',
		    readOnly:true
	   });
   combo.on('change',f_format);
	   
	var formScoreFormat = new Ext.form.FormPanel({
	      labelAlign:'right',
	      autoWidth:true,
	      region:'north',
	      height:50,
	      frame:true,
	      el:'score_format_form',
	      items:[combo]  
	});
	formScoreFormat.render();	   

        var store5={'fields':['value','text'],data:[['','请选择'],['0','无成绩'],['-1','优'],['-2','良'],['-3','中'],['-4','及格'],['-5','不及格'],['-6','通过']]};
  	    var combo5=new Ext.form.ComboBox({
	    	store:new Ext.data.SimpleStore(store5),
	   	    emptyText:'请选择',
		    mode:'local',
		    triggerAction:'all',
		    valueField:'value',
		    displayField:'text',
		    readOnly:true
	   });
	   renderer5=Ext.ux.comboBoxRenderer(combo5),
	   editor5=new Ext.grid.GridEditor(combo5)

        var store2={'fields':['value','text'],data:[['','请选择'],['0','无成绩'],['-4','及格'],['-5','不及格']]};
  	    var combo2=new Ext.form.ComboBox({
	    	store:new Ext.data.SimpleStore(store2),
	   	    emptyText:'请选择',
		    mode:'local',
		    triggerAction:'all',
		    valueField:'value',
		    displayField:'text',
		    readOnly:true
	   });
	   renderer2=Ext.ux.comboBoxRenderer(combo2),
	   editor2=new Ext.grid.GridEditor(combo2)

		   

});


function f_back(){
   history.back();
}


function f_add(tableName){
  globalScope._add(tableName);
}

function f_format(combo){
  var format=combo.getValue();
  var grid=globalScope.grid.get("<c:out value='${model.tableName}'/>");
  var cm=grid.getColumnModel();
  var cols;
  if(format=='01'){//五级制
	  cols=cm.getColumnsBy(function(c,i){
		if(c.dataIndex=='SCORE'||c.dataIndex=='SCORE2'){
			c.renderer=renderer5;
			c.editor=editor5;
			c.header='<b>'+c.header+'</b>';
		}
		if(c.dataIndex=='SCORE_NATURE'){
			c.header='<b>'+c.header+'</b>';
		}
		return true;  
	  });
  }else  if(format=='02'){//百分制
	  cols=cm.getColumnsBy(function(c,i){
		if(c.dataIndex=='SCORE'||c.dataIndex=='SCORE2'){
			var f=new Ext.form.NumberField({'allowBlank':false,'maxLength':10});
			var editor=new Ext.grid.GridEditor(f);
			c.editor=editor;
			c.renderer='';
			c.header='<b>'+c.header+'</b>';
		}
		if(c.dataIndex=='SCORE_NATURE'){
			c.header='<b>'+c.header+'</b>';
		}
		return true;  
	  });
  }else{//二级制
	  cols=cm.getColumnsBy(function(c,i){
		if(c.dataIndex=='SCORE'||c.dataIndex=='SCORE2'){
			c.renderer=renderer2;
			c.editor=editor2;
			c.header='<b>'+c.header+'</b>';
		}
		if(c.dataIndex=='SCORE_NATURE'){
			c.header='<b>'+c.header+'</b>';
		}
		return true;  
	  });
    
  }
  var store=grid.getStore();
  store.filterBy(function(record){
    var scoreFormat=record.get('SCORE_FORMAT'); 
    if(scoreFormat==format) return true;
  });
  grid.reconfigure(store,cm);
}

function f_delete(tableName){
  globalScope._delete(tableName);
} 

function f_cancel(tableName){
  globalScope._cancel(tableName);
}

function f_save(tableName,url){
  var grid=globalScope.grid.get('V_ORIGINAL_SCORE_DETAIL');
  var m=grid.getStore().getModifiedRecords(); 
  var recs=[];
  for(var i=0;i<m.length;i++){
    var score1=m[i].get('SCORE');
    var score2=m[i].get('SCORE2');
    if(score1!=score2){
      var sname=m[i].get('STUDENT_NAME');
      recs.push(m[i]);
    }
  }
  if(recs.length>0){
    grid.getSelectionModel().selectRecords(recs);
    Ext.Msg.alert('错误',"选中的记录,输入的两次成绩不一致!");
    return;
  }
  globalScope._simpleSave({tableName:'V_ORIGINAL_SCORE_DETAIL',saveTableName:'T_ORIGINAL_SCORE',url:'ajax/score/updateAndConfirm.html'});
}

function f_query(tableName){
    globalScope._query(tableName);
}

function f_gotoPage(pageNo,rowsOfPage,pageCount,rowCount,conditoin){
  var schoolYear="<c:out value='${model.parameter.SCHOOL_YEAR}'/>";
  var schoolSemester="<c:out value='${model.parameter.SCHOOL_SEMESTER}'/>";
  var studentNo="<c:out value='${model.parameter.STUDENT_NO}'/>";
  var classNo="<c:out value='${model.parameter.CLASS_NO}'/>";
  var courseNo="<c:out value='${model.parameter.COURSE_NO}'/>";
  
  var postData={'SCHOOL_YEAR':schoolYear,'SCHOOL_SEMESTER':schoolSemester,'STUDENT_NO':studentNo,'CLASS_NO':classNo,'COURSE_NO':courseNo};
  globalScope._gotoPage({spanName:"g_pageSpan_<c:out value='${model.tableName}'/>",pageNo:pageNo,rowsOfPage:rowsOfPage,pageCount:pageCount,rowCount:rowCount,condition:conditoin,tableName:"<c:out value='${model.tableName}'/>"},postData);
}
</script>
